<?php /* Update Rol Controller */
	require_once('modules/roles/actions/update/scripts/validate-rol.php');
	$students_actions = array('todo','no-regulares','potenciales','sin-confirmar','disponibles','delete','update','read','create','default');
	$groups_actions = array('plan','accountancy','read-message','send-message','create-workshop','read-workshop','calendar','todo','inactivos','delete','update-students','update','read','create','default');

	$_students = array('students',$students_actions);
	$_groups = array('groups',$groups_actions);

	$arr_modules = array($_students,$_groups);

	if (isset($_POST['form-action'])) {
		$validacion = validarRol();
		if (!empty($validacion)) { //fallo validacion
			$arr_permisos = explode('-', $rol->get('roles','permisos'));
				for ($i=0;$i<count($arr_modules);$i++) {
					$current_bin = convertHexToBin($arr_permisos[$i],4);
					$current_permisos = str_split($current_bin);
					//var_dump($current_permisos);
					$diff = (count($current_permisos)-count($arr_modules[$i][1]));
					//var_dump($diff);
					for ($ii=0;$ii<count($arr_modules[$i][1]);$ii++) {
						//var_dump($diff-1+$ii); 
						$rol->set('checklist',$arr_modules[$i][0].'-'.$arr_modules[$i][1][$ii],$current_permisos[($diff+$ii)]);
					}
					//var_dump($rol->data);
				}
				//echo "<hr>";
			require_once('modules/roles/actions/update/view/update-rol.php');
		} else { //si valido correcto
            /*
			$rol->update("id=".(int)$glb_uri[2]);
			require_once('modules/roles/actions/list/index.php');
            */
			require_once('modules/roles/actions/update/view/update-rol.php');
		}
	} else {
		if (@(int)$glb_uri[2] > 0) { //valida que la id ingresa es valida.
			$result = $rol->getAllFrom((int)$glb_uri[2]);
			if ($result) { //valida si existe la id.
				$arr_permisos = explode('-', $rol->get('roles','permisos'));
				for ($i=0;$i<count($arr_modules);$i++) {
					$current_bin = convertHexToBin($arr_permisos[$i],4);
					$current_permisos = str_split($current_bin);
					//var_dump($current_permisos);
					$diff = (count($current_permisos)-count($arr_modules[$i][1]));
					//var_dump($diff);
					for ($ii=0;$ii<count($arr_modules[$i][1]);$ii++) {
						//var_dump($diff-1+$ii); 
						$rol->set('checklist',$arr_modules[$i][0].'-'.$arr_modules[$i][1][$ii],$current_permisos[($diff+$ii)]);
					}
					//var_dump($rol->data);
				}
				//echo "<hr>";
				require_once('modules/roles/actions/update/view/update-rol.php');
			} else {
				echo '<strong>No existe el rol solicitado.</strong>';
			}
		} else {
			echo '<strong>Pagina invalida.</strong>';
		}
	}
?>